package org.stwy.comm.base;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;

import org.apache.commons.lang.StringUtils;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.rap.common.annotation.MetaData;
import com.rap.common.entity.AuditableEntity;
import com.rap.frame.security.ShiroUser;
import com.rap.modules.sys.user.UserEntity;

@MappedSuperclass
public class BaseRecordsEntity extends AuditableEntity {
	private static final long serialVersionUID = 1L;
	
	@MetaData(value="编码",comments="用于标识同一物体")
	@Column(length=20)
	protected Long theCode ;
	
	@MetaData(value="记录开始时间",comments="")
	
	protected Date beginTs ;
	
	@MetaData(value="记录开始时间",comments="")
	
	//是否有效
	protected Integer valid = 1 ;
	
	public Long getTheCode() {
		return theCode;
	}

	public void setTheCode(Long theCode) {
		this.theCode = theCode;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getBeginTs() {
		return beginTs;
	}

	public void setBeginTs(Date beginTs) {
		this.beginTs = beginTs;
	}
	
	public Integer getValid() {
		return valid;
	}

	public void setValid(Integer valid) {
		this.valid = valid;
	}

	public void prePersist(){
		UserEntity user = ShiroUser.getCurrentUserEntity();
		if (StringUtils.isNotBlank(user.getUuid())){
			this.creator = user.getUuid();
			this.modifier = user.getUuid();
		}
		super.prePersist();
	}
	public void preUpdate(){
		UserEntity user = ShiroUser.getCurrentUserEntity();
		if (StringUtils.isNotBlank(user.getUuid())){
			this.modifier = user.getUuid();
		}
		this.modifyTs = new Date();
	}

}
